local skel = fk.CreateSkill {
  name = "emo__tanlan",
}

Fk:loadTranslationTable{
  ["emo__tanlan"] = "贪婪",
  [":emo__tanlan"] = "出牌阶段限一次，你可以将一张牌置于牌堆顶，从牌堆底摸牌直到摸到点数为X的牌或摸了X张牌（X为此牌点数）",
  ["#emo__tanlan-prompt"] = "贪婪:将一张牌置于牌堆顶，重复从牌堆底摸牌",
}

skel:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#emo__tanlan-prompt",
  card_num = 1,
  target_num = 0,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0 and not player:isNude()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local x = Fk:getCardById(effect.cards[1]).number
    room:moveCardTo(effect.cards, Card.DrawPile, nil, fk.ReasonPut, skel.name, nil, false, player)
    for _ = 1, x do
      if player.dead then break end
      local cid = player:drawCards(1, skel.name, "bottom")[1]
      if cid and Fk:getCardById(cid).number == x then break end
    end
  end,
})

return skel
